﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RakutenProxy.Model.Rakuten
{
    /// <summary>
    /// Category is similar to genre in Rakuten
    /// </summary>
    public class Category:IEquatable<RakutenProxy.Model.NopCommerce.Category>
    {
        public Category()
        {
            Products = new List<Product>();
            SubCategories = new List<Category>();
        }

        public int CategoryId { get; set; }
        public string CategoryName { get; set; }
        public int? ParentCategoryId { get; set; }
        public string CategoryUrl { get; set; }

        public virtual ICollection<Product> Products { get; set; }
        public virtual ICollection<Category> SubCategories { get; set; }
        public virtual Category ParentCategory { get; set; }


        public bool Equals(NopCommerce.Category other)
        {
            var name = this.CategoryName.Equals(other.Name);
            var parentCategoryId = this.ParentCategoryId.HasValue ? this.ParentCategoryId.Value : 0;
            var parentCategory = parentCategoryId.Equals(other.ParentCategoryId);

            return name && parentCategory;
        }
    }
}
